﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using GraphCompiler.Core.Parsing;
using GraphCompiler.Core;
using GraphCompiler.Core.SyntaxRepresentation;
using GraphCompiler.Core.Exceptions;

namespace GraphCompiler.Specification.Parsing
{
    [TestFixture]
    public class ArrowParserSpecs
    {
        ArrowParser _parser;
        
        [SetUp]
        public void SetUp()
        {
            _parser = new ArrowParser();
        }

        [Test]
        public void GivenSimpleArrowDeclaration_ReturnsNodeWithSpecifiedFromAndToBoxeNames()
        {
            var tokens = new TokenCollection("leftBox", "->", "rightBox");

            ArrowNode expectedNode = new ArrowNode("leftBox", "rightBox");

            ArrowNode actualNode = _parser.ParseTypedNode(tokens);

            Assert.AreEqual(expectedNode, actualNode);
        }

        [ExpectedException(typeof(SyntaxErrorException))]
        [Test]
        public void GivenEmptyInput_RaisesError()
        {
            _parser.ParseTypedNode(new TokenCollection());
        }

        [ExpectedException(typeof(SyntaxErrorException))]
        [Test]
        public void GivenInvalidInput_RaisesError()
        {
            _parser.ParseTypedNode(new TokenCollection("a", "!", "b"));
        }

        [Test]
        public void GivenEmptyInput_IsNotApplicable()
        {
            bool isApplicable = _parser.IsApplicable(new TokenCollection());
            Assert.IsFalse(isApplicable);
        }

        [Test]
        public void GivenInvalidInput_IsNotApplicable()
        {
            bool isApplicable = _parser.IsApplicable(new TokenCollection("a", "!", "b"));
            Assert.IsFalse(isApplicable);
        }

        [Test]
        public void GivenValidInput_IsApplicable()
        {
            bool isApplicable = _parser.IsApplicable(new TokenCollection("a", "->", "b"));
            Assert.IsTrue(isApplicable);
        }
    }
}
